#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

int main()
{
    // 自动创建并初始化文件
    int fd = open("test.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
    write(fd, "aaaaa\nbbbbbb\nccccc\n", 16);
    lseek(fd, 5, SEEK_SET);

    pid_t pid = fork();
    if (pid == 0)
    {
        write(fd, "Child writes\n", 13);
    }
    else
    {
        write(fd, "Parent writes\n", 14);
    }
    close(fd);
    return 0;
}